package com.spark.check

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.spark.check.model.TaskModel
import com.spark.common.BaseFragment
import com.spark.common.Const
import com.spark.common.ext.wrapIO
import com.spark.common.net.Http
import kotlinx.android.synthetic.main.frag_to_chk_approve_detail.*

/**
 * the detail of the check & approve task
 */
class ToChkApproveDetailFragment : BaseFragment() {
    override fun contentResId(): Int {
        return R.layout.frag_to_chk_approve_detail
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iv_back.setOnClickListener { pop() }
        val taskAdapter = TasksAdpater(R.layout.item_task)
        recy_tasks.adapter = taskAdapter
        recy_tasks.layoutManager = LinearLayoutManager(context)

        taskAdapter.addData(mutableListOf(TaskModel.mock(), TaskModel.mock(), TaskModel.mock(), TaskModel.mock(), TaskModel.mock(), TaskModel.mock()))
    }

    /**
     * 获取待检查项的详情
     */
    private fun fetchCheckApproveDetail() {
        val params = mutableMapOf(
                Pair(Const.qr_taskid, "$id"),
                Pair(Const.categoryid, "typeid")
        )
        activity?.apply {
            Http.request()
                    .rxPost("${Const.base_url}${Const.act_stdchk_category_list}", params)
                    .wrapIO()
                    .subscribe(
                            {

                            },
                            {
                                it.printStackTrace()
                                hideLoader()
                            },
                            {
                                hideLoader()
                            },
                            {
                                dispose = it
                                loading()
                            }
                    )
        }
    }
}
